#include "MainWindow.h"
#include <SDL/SDL_ttf.h>
#include "AButton.h"

unsigned char const AButton::ButtonState::RELEASED = 0;
unsigned char const AButton::ButtonState::PRESSED = 1;
unsigned char const AButton::ButtonState::CLICKED = 2;
unsigned char const AButton::ButtonState::HOVERED = 3;

AButton::AButton(IScreen* _caller, std::string const& _text)
: m_currentState(AButton::ButtonState::RELEASED), m_caller(_caller), m_string(_text)
{
}

AButton::~AButton()
{
}

bool AButton::draw(SDL_Surface* _screen)
{
	if (m_currentSprite != NULL)
	{
		if (m_currentSprite->Surface != NULL)
		{
			SDL_BlitSurface(m_currentSprite->Surface, NULL, _screen, &m_position);
			if (m_text.Surface != NULL)
			{
				SDL_BlitSurface(m_text.Surface, NULL, _screen, &m_text.Position);
			}
		}
	}
	return (true);
}

void AButton::initText()
{
	if (m_string.empty() == false)
	{
		SDL_Color black = {0, 0, 0};
		TTF_Font* f = MainWindow::Font();
		m_text.Surface = TTF_RenderText_Blended(f, m_string.c_str(), black);
	}
}

void AButton::setCurrentState(char _state)
{
	m_currentState = _state;
}

void AButton::setCallBack(ButtonCallBack _callBack)
{
	m_callBack = _callBack;
}

bool AButton::useCallBack()
{
	//return ((this->*CallBack)());
	return (true);
}

void AButton::setCaller(IScreen* _caller)
{
	m_caller = _caller;
}

IScreen* AButton::getCaller()
{
	return (m_caller);
}

Image* AButton::getCurrentSprite()
{
	return (m_currentSprite);
}

char AButton::getCurrentState() const
{
	return (m_currentState);
}

SDL_Rect& AButton::getPosition()
{
	return (m_position);
}

ButtonCallBack AButton::getCallBack()
{
	return (m_callBack);
}

void AButton::setPosition(int _x, int _y)
{
	if (m_currentSprite != NULL)
	{
		if (m_currentSprite->Surface != NULL)
		{
			m_position.x = _x;
			m_position.y = _y;
		}
	}
}